﻿USE [master]
GO
/****** Object:  Database [GenStudioTestDb]    Script Date: 10/31/2008 10:47:39 ******/
IF  EXISTS (SELECT name FROM sys.databases WHERE name = N'GenStudioTestDb')
DROP DATABASE [GenStudioTestDb]
GO
CREATE DATABASE [GenStudioTestDb]
GO
USE [GenStudioTestDb]
GO
/****** Object:  ForeignKey [FK_Address_City]    Script Date: 10/31/2008 10:49:10 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Address_City]') AND parent_object_id = OBJECT_ID(N'[dbo].[Address]'))
ALTER TABLE [dbo].[Address] DROP CONSTRAINT [FK_Address_City]
GO
/****** Object:  ForeignKey [FK_Address_Person]    Script Date: 10/31/2008 10:49:10 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Address_Person]') AND parent_object_id = OBJECT_ID(N'[dbo].[Address]'))
ALTER TABLE [dbo].[Address] DROP CONSTRAINT [FK_Address_Person]
GO
/****** Object:  ForeignKey [FK_PersonEx_Person]    Script Date: 10/31/2008 10:49:13 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PersonEx_Person]') AND parent_object_id = OBJECT_ID(N'[dbo].[PersonEx]'))
ALTER TABLE [dbo].[PersonEx] DROP CONSTRAINT [FK_PersonEx_Person]
GO
/****** Object:  ForeignKey [FK_SuperHero_Person]    Script Date: 10/31/2008 10:49:14 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_SuperHero_Person]') AND parent_object_id = OBJECT_ID(N'[dbo].[SuperHero]'))
ALTER TABLE [dbo].[SuperHero] DROP CONSTRAINT [FK_SuperHero_Person]
GO
/****** Object:  View [dbo].[Person_Full]    Script Date: 10/31/2008 10:49:14 ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Person_Full]'))
DROP VIEW [dbo].[Person_Full]
GO
/****** Object:  Synonym [dbo].[CitySynonym]    Script Date: 10/31/2008 10:49:08 ******/
IF  EXISTS (SELECT * FROM sys.synonyms WHERE name = N'CitySynonym')
DROP SYNONYM [dbo].[CitySynonym]
GO
/****** Object:  StoredProcedure [dbo].[City_GetAll]    Script Date: 10/31/2008 10:49:08 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[City_GetAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[City_GetAll]
GO
/****** Object:  Synonym [dbo].[City_SP_Synonym]    Script Date: 10/31/2008 10:49:08 ******/
IF  EXISTS (SELECT * FROM sys.synonyms WHERE name = N'City_SP_Synonym')
DROP SYNONYM [dbo].[City_SP_Synonym]
GO
/****** Object:  Table [dbo].[SuperHero]    Script Date: 10/31/2008 10:49:14 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SuperHero]') AND type in (N'U'))
DROP TABLE [dbo].[SuperHero]
GO
/****** Object:  Table [dbo].[Address]    Script Date: 10/31/2008 10:49:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Address]') AND type in (N'U'))
DROP TABLE [dbo].[Address]
GO
/****** Object:  Table [dbo].[Person]    Script Date: 10/31/2008 10:49:13 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Person]') AND type in (N'U'))
DROP TABLE [dbo].[Person]
GO
/****** Object:  Table [dbo].[PersonEx]    Script Date: 10/31/2008 10:49:13 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PersonEx]') AND type in (N'U'))
DROP TABLE [dbo].[PersonEx]
GO
/****** Object:  Table [dbo].[City]    Script Date: 10/31/2008 10:49:11 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[City]') AND type in (N'U'))
DROP TABLE [dbo].[City]
GO
/****** Object:  Synonym [dbo].[City_SP_Synonym]    Script Date: 10/31/2008 10:49:08 ******/
IF NOT EXISTS (SELECT * FROM sys.synonyms WHERE name = N'City_SP_Synonym')
CREATE SYNONYM [dbo].[City_SP_Synonym] FOR [AppTest].[dbo].[City_GetAll]
GO
/****** Object:  Table [dbo].[Person]    Script Date: 10/31/2008 10:49:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Person]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Person](
	[PersonId] [uniqueidentifier] NOT NULL,
	[Version] [int] NOT NULL,
	[EditedById] [uniqueidentifier] NOT NULL,
	[EditedDate] [datetime] NOT NULL,
	[IsDeleted] [bit] NOT NULL,
 CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED 
(
	[PersonId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Synonym [dbo].[CitySynonym]    Script Date: 10/31/2008 10:49:08 ******/
IF NOT EXISTS (SELECT * FROM sys.synonyms WHERE name = N'CitySynonym')
CREATE SYNONYM [dbo].[CitySynonym] FOR [AppTest].[dbo].[City]
GO
/****** Object:  Table [dbo].[City]    Script Date: 10/31/2008 10:49:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[City]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[City](
	[CityId] [uniqueidentifier] NOT NULL,
	[Title] [nvarchar](100) NOT NULL,
	[Version] [int] NOT NULL,
	[EditedById] [uniqueidentifier] NOT NULL,
	[EditedDate] [datetime] NOT NULL,
	[IsDeleted] [bit] NOT NULL,
 CONSTRAINT [PK_City] PRIMARY KEY CLUSTERED 
(
	[CityId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Address]    Script Date: 10/31/2008 10:49:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Address]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Address](
	[AddressId] [uniqueidentifier] NOT NULL,
	[PersonId] [uniqueidentifier] NOT NULL,
	[CityId] [uniqueidentifier] NOT NULL,
	[Version] [int] NOT NULL,
	[EditedById] [uniqueidentifier] NOT NULL,
	[EditedDate] [datetime] NOT NULL,
	[IsDeleted] [bit] NOT NULL,
 CONSTRAINT [PK_Address] PRIMARY KEY CLUSTERED 
(
	[AddressId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[SuperHero]    Script Date: 10/31/2008 10:49:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SuperHero]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[SuperHero](
	[PersonId] [uniqueidentifier] NOT NULL,
	[Title] [nvarchar](100) NOT NULL,
 CONSTRAINT [PK_SuperHero] PRIMARY KEY CLUSTERED 
(
	[PersonId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[PersonEx]    Script Date: 10/31/2008 10:49:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PersonEx]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PersonEx](
	[PersonId] [uniqueidentifier] NOT NULL,
	[LifeStory] [nvarchar](max) NOT NULL
) ON [PRIMARY]
END
GO
/****** Object:  View [dbo].[Person_Full]    Script Date: 10/31/2008 10:49:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Person_Full]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[Person_Full]
AS
SELECT     dbo.Person.PersonId, dbo.Person.Version, dbo.Person.EditedById, dbo.Person.EditedDate, dbo.Person.IsDeleted, dbo.PersonEx.LifeStory
FROM         dbo.Person INNER JOIN
                      dbo.PersonEx ON dbo.Person.PersonId = dbo.PersonEx.PersonId
'
GO
IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_DiagramPane1' , N'SCHEMA',N'dbo', N'VIEW',N'Person_Full', NULL,NULL))
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "Person"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 190
               Right = 190
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "PersonEx"
            Begin Extent = 
               Top = 9
               Left = 377
               Bottom = 135
               Right = 529
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Person_Full'
GO
IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_DiagramPaneCount' , N'SCHEMA',N'dbo', N'VIEW',N'Person_Full', NULL,NULL))
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Person_Full'
GO
/****** Object:  StoredProcedure [dbo].[City_GetAll]    Script Date: 10/31/2008 10:49:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[City_GetAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[City_GetAll]

AS

SELECT * FROM City
' 
END
GO
/****** Object:  ForeignKey [FK_Address_City]    Script Date: 10/31/2008 10:49:10 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Address_City]') AND parent_object_id = OBJECT_ID(N'[dbo].[Address]'))
ALTER TABLE [dbo].[Address]  WITH CHECK ADD  CONSTRAINT [FK_Address_City] FOREIGN KEY([CityId])
REFERENCES [dbo].[City] ([CityId])
GO
ALTER TABLE [dbo].[Address] CHECK CONSTRAINT [FK_Address_City]
GO
/****** Object:  ForeignKey [FK_Address_Person]    Script Date: 10/31/2008 10:49:10 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Address_Person]') AND parent_object_id = OBJECT_ID(N'[dbo].[Address]'))
ALTER TABLE [dbo].[Address]  WITH CHECK ADD  CONSTRAINT [FK_Address_Person] FOREIGN KEY([PersonId])
REFERENCES [dbo].[Person] ([PersonId])
GO
ALTER TABLE [dbo].[Address] CHECK CONSTRAINT [FK_Address_Person]
GO
/****** Object:  ForeignKey [FK_PersonEx_Person]    Script Date: 10/31/2008 10:49:13 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PersonEx_Person]') AND parent_object_id = OBJECT_ID(N'[dbo].[PersonEx]'))
ALTER TABLE [dbo].[PersonEx]  WITH CHECK ADD  CONSTRAINT [FK_PersonEx_Person] FOREIGN KEY([PersonId])
REFERENCES [dbo].[Person] ([PersonId])
GO
ALTER TABLE [dbo].[PersonEx] CHECK CONSTRAINT [FK_PersonEx_Person]
GO
/****** Object:  ForeignKey [FK_SuperHero_Person]    Script Date: 10/31/2008 10:49:14 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_SuperHero_Person]') AND parent_object_id = OBJECT_ID(N'[dbo].[SuperHero]'))
ALTER TABLE [dbo].[SuperHero]  WITH CHECK ADD  CONSTRAINT [FK_SuperHero_Person] FOREIGN KEY([PersonId])
REFERENCES [dbo].[Person] ([PersonId])
GO
ALTER TABLE [dbo].[SuperHero] CHECK CONSTRAINT [FK_SuperHero_Person]
GO
